import request from '@/utils/request'

export interface Article {
  id?: number | null | undefined
  title: string
  content: string
  categoryId: string
  articleCover: string
}

export interface ArticleListParams {
  page: number
  pageSize: number
  title?: string
}

// 获取文章列表
export const getArticles = (params: ArticleListParams) => {
  return request({
    url: '/admin/article/search',
    method: 'get',
    params,
  })
}

// 获取文章详情
export const getArticleDetail = (id: number) => {
  return request({
    url: `/admin/article/${id}`,
    method: 'get',
  })
}

// 创建文章
export const createArticle = (data: Article) => {
  return request({
    url: '/admin/article/add',
    method: 'post',
    data,
  })
}

// 更新文章
export const updateArticle = (data: Article) => {
  return request({
    url: `/admin/article/update`,
    method: 'put',
    data,
  })
}

// 删除文章
export const deleteArticle = (id: number) => {
  return request({
    url: `/admin/article/${id}`,
    method: 'delete',
  })
}

// 上传图片
export const uploadImage = (data: FormData) => {
  return request({
    url: '/api/image/upload',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}
// 获取文章标签
export const getArticleTags = () => {
  return request({
    url: '/category/list',
    method: 'get',
  })
}
